#!/bin/bash

clear
echo "===================================="
echo "梦幻西游数字资产管理系统"
echo "===================================="
echo ""

# 检查Python是否安装
if ! command -v python3 &> /dev/null; then
    echo "[错误] 未检测到Python3，请先安装Python 3.7+"
    exit 1
fi

echo "[1/3] 检测Python环境... OK"
echo ""

# 自动安装依赖包
echo "[2/3] 安装/检查依赖包..."
pip3 install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
if [ $? -ne 0 ]; then
    echo "[警告] 阿里云镜像失败，尝试清华镜像..."
    pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
    if [ $? -ne 0 ]; then
        echo "[警告] 清华镜像失败，尝试使用默认源..."
        pip3 install -r requirements.txt
        if [ $? -ne 0 ]; then
            echo "[错误] 依赖安装失败，请检查网络连接"
            exit 1
        fi
    fi
fi
echo "依赖包准备完成！"
echo ""

echo "[3/3] 启动系统..."
echo ""
echo "===================================="
echo "系统已启动！"
echo "访问地址: http://127.0.0.1:5000"
echo "按 Ctrl+C 可以停止服务器"
echo "===================================="
echo ""

# 启动Flask应用
python3 app.py

